# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/17 下午3:48
 @Author  : tgy
 
"""
import re


def test01():
    ...
    res = re.findall(r'^\d?$', '2')
    print(res)
    # *后面加?，表示非贪婪模式
    res = re.findall(r'a.*?b', 'a123b atgyb')
    print(res)


def test02():
    # findall的pattern中如果没有分组，则查找匹配到的元素，如果有分组，则返回分组匹配到的元素
    res = re.findall(r'href="(.*?)"', '<a href="http://www.baidu.com">点击</a>')
    print(res)
    print(re.findall('compan(?:y|ies)', 'Too many companies have gone bankrupt, and the next one is my company'))

    print(re.search(r'ab(\d+)c(\d+)', 'ab12c34'))

if __name__ == '__main__':
    ...
    test02()
